package com.jiankangjin.appspos.controller;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jiankangjin.appspos.services.CheckServices;
import com.jiankangjin.appspos.util.StringUtil;
import com.jiankangjin.appspos.vo.CheckVersionVo;

@Controller
public class VersionController {
	private static final transient Log logger = LogFactory.getLog(VersionController.class);
	
	@Autowired
	private CheckServices checkServices;
	
	/**
	 * 软件版本检查
	 */
	@RequestMapping(value="/check_version", method=RequestMethod.POST)
	@ResponseBody
	public CheckVersionVo checkVersion(
			@RequestParam(required = true) String terminal_type,
			@RequestParam(required = true) String terminal_ver,
			@RequestParam(required = true) String terminal_id,
			@RequestParam(required = true) String sign) {
		StringBuilder sb = new StringBuilder();
		sb.append("terminal_type=" + terminal_type);
		sb.append(" terminal_ver=" + terminal_ver);
		sb.append(" terminal_id=" + terminal_id);
		sb.append(" sign=" + sign);
		if (logger.isInfoEnabled()) {
			logger.info("版本接口检查接口:" + sb);
		}
		CheckVersionVo checkVersionVo = new CheckVersionVo();
		checkVersionVo.setResp_status("9999");
		checkVersionVo.setSign("appSPOS_sign");
		if (StringUtil.isEmpty(terminal_type)) {
			checkVersionVo.setMsg("terminal_type不能为空");
			return checkVersionVo;
		}
		if (StringUtil.isEmpty(terminal_ver)) {
			checkVersionVo.setMsg("terminal_ver不能为空");
			return checkVersionVo;
		}
		if (StringUtil.isEmpty(terminal_id)) {
			checkVersionVo.setMsg("terminal_id不能为空");
			return checkVersionVo;
		}
		if (StringUtil.isEmpty(sign)) {
			checkVersionVo.setMsg("sign不能为空");
			return checkVersionVo;
		}
		return 	checkServices.checkVersion(terminal_type, terminal_ver, terminal_id);
	}
}
